{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "notebookRunGroups": {
     "groupValue": "1"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as up"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "导入数据\n",
    "导入的csv文件，是中国股票市场上证指数000001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             Day   Preclose       Open    Highest     Lowest      Close  \\\n",
      "0     1990/12/19               96.0500    99.9800    95.7900    99.9800   \n",
      "1     1990/12/20      99.98   104.3000   104.3900    99.9800   104.3900   \n",
      "2     1990/12/21     104.39   109.0700   109.1300   103.7300   109.1300   \n",
      "3     1990/12/24     109.13   113.5700   114.5500   109.1300   114.5500   \n",
      "4     1990/12/25     114.55   120.0900   120.2500   114.5500   120.2500   \n",
      "...          ...        ...        ...        ...        ...        ...   \n",
      "8205   2024/7/25  2901.9518  2891.8918  2897.7674  2872.8497  2886.7416   \n",
      "8206   2024/7/26  2886.7416  2885.9953  2899.1162  2875.3959  2890.8973   \n",
      "8207   2024/7/29  2890.8973  2889.4726  2898.9512  2878.5825  2891.8453   \n",
      "8208   2024/7/30  2891.8453  2885.2152  2885.2152  2865.1493  2879.2996   \n",
      "8209   2024/7/31  2879.2996  2877.5409  2940.5927  2876.3009  2938.7493   \n",
      "\n",
      "           Volume         Money  \n",
      "0          126000  4.940000e+05  \n",
      "1           19700  8.400000e+04  \n",
      "2            2800  1.600000e+04  \n",
      "3            3200  3.100000e+04  \n",
      "4            1500  6.000000e+03  \n",
      "...           ...           ...  \n",
      "8205  27463950000  2.732820e+11  \n",
      "8206  27838753600  2.754430e+11  \n",
      "8207  25689972700  2.600950e+11  \n",
      "8208  26247883700  2.694770e+11  \n",
      "8209  41272341700  4.188720e+11  \n",
      "\n",
      "[8210 rows x 8 columns]\n"
     ]
    }
   ],
   "source": [
    "#这里的代码是为了演示如何读取csv文件\n",
    "data=pd.read_csv(\"D:/data.csv\")\n",
    "#打印出data的前5行和后5行\n",
    "data\n",
    "print(data)\n",
    "#默认只呈现最后一行"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数据切片"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "选取单列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       1990/12/19\n",
       "1       1990/12/20\n",
       "2       1990/12/21\n",
       "3       1990/12/24\n",
       "4       1990/12/25\n",
       "           ...    \n",
       "8205     2024/7/25\n",
       "8206     2024/7/26\n",
       "8207     2024/7/29\n",
       "8208     2024/7/30\n",
       "8209     2024/7/31\n",
       "Name: Day, Length: 8210, dtype: object"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['Day']\n",
    "#调取一列数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "选取多列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990/12/19</td>\n",
       "      <td>99.9800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990/12/20</td>\n",
       "      <td>104.3900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990/12/21</td>\n",
       "      <td>109.1300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990/12/24</td>\n",
       "      <td>114.5500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990/12/25</td>\n",
       "      <td>120.2500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8205</th>\n",
       "      <td>2024/7/25</td>\n",
       "      <td>2886.7416</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8206</th>\n",
       "      <td>2024/7/26</td>\n",
       "      <td>2890.8973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8207</th>\n",
       "      <td>2024/7/29</td>\n",
       "      <td>2891.8453</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8208</th>\n",
       "      <td>2024/7/30</td>\n",
       "      <td>2879.2996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8209</th>\n",
       "      <td>2024/7/31</td>\n",
       "      <td>2938.7493</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8210 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             Day      Close\n",
       "0     1990/12/19    99.9800\n",
       "1     1990/12/20   104.3900\n",
       "2     1990/12/21   109.1300\n",
       "3     1990/12/24   114.5500\n",
       "4     1990/12/25   120.2500\n",
       "...          ...        ...\n",
       "8205   2024/7/25  2886.7416\n",
       "8206   2024/7/26  2890.8973\n",
       "8207   2024/7/29  2891.8453\n",
       "8208   2024/7/30  2879.2996\n",
       "8209   2024/7/31  2938.7493\n",
       "\n",
       "[8210 rows x 2 columns]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[['Day','Close']]\n",
    "#调取多列数据框数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "选取行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Money</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4092</th>\n",
       "      <td>2007/8/23</td>\n",
       "      <td>4980.07</td>\n",
       "      <td>5002.84</td>\n",
       "      <td>5050.38</td>\n",
       "      <td>4968.33</td>\n",
       "      <td>5032.49</td>\n",
       "      <td>9930942800</td>\n",
       "      <td>1.530000e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4093</th>\n",
       "      <td>2007/8/24</td>\n",
       "      <td>5032.49</td>\n",
       "      <td>5070.65</td>\n",
       "      <td>5125.36</td>\n",
       "      <td>5052.24</td>\n",
       "      <td>5107.67</td>\n",
       "      <td>10899563600</td>\n",
       "      <td>1.650000e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4094</th>\n",
       "      <td>2007/8/27</td>\n",
       "      <td>5107.67</td>\n",
       "      <td>5144.82</td>\n",
       "      <td>5192.06</td>\n",
       "      <td>5092.08</td>\n",
       "      <td>5150.12</td>\n",
       "      <td>11615424400</td>\n",
       "      <td>1.760000e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4095</th>\n",
       "      <td>2007/8/28</td>\n",
       "      <td>5150.12</td>\n",
       "      <td>5134.14</td>\n",
       "      <td>5209.51</td>\n",
       "      <td>5058.45</td>\n",
       "      <td>5194.69</td>\n",
       "      <td>10543673900</td>\n",
       "      <td>1.670000e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4096</th>\n",
       "      <td>2007/8/29</td>\n",
       "      <td>5194.69</td>\n",
       "      <td>5147.71</td>\n",
       "      <td>5204.53</td>\n",
       "      <td>5063.41</td>\n",
       "      <td>5109.43</td>\n",
       "      <td>10082413900</td>\n",
       "      <td>1.620000e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5985</th>\n",
       "      <td>2015/6/9</td>\n",
       "      <td>5131.88</td>\n",
       "      <td>5145.98</td>\n",
       "      <td>5147.45</td>\n",
       "      <td>5042.96</td>\n",
       "      <td>5113.53</td>\n",
       "      <td>72989381800</td>\n",
       "      <td>1.150000e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5986</th>\n",
       "      <td>2015/6/10</td>\n",
       "      <td>5113.53</td>\n",
       "      <td>5049.20</td>\n",
       "      <td>5164.16</td>\n",
       "      <td>5001.49</td>\n",
       "      <td>5106.04</td>\n",
       "      <td>59696900100</td>\n",
       "      <td>1.010000e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5987</th>\n",
       "      <td>2015/6/11</td>\n",
       "      <td>5106.04</td>\n",
       "      <td>5101.44</td>\n",
       "      <td>5122.46</td>\n",
       "      <td>5050.77</td>\n",
       "      <td>5121.59</td>\n",
       "      <td>56399052200</td>\n",
       "      <td>9.750000e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5988</th>\n",
       "      <td>2015/6/12</td>\n",
       "      <td>5121.59</td>\n",
       "      <td>5143.34</td>\n",
       "      <td>5178.19</td>\n",
       "      <td>5103.40</td>\n",
       "      <td>5166.35</td>\n",
       "      <td>62562785400</td>\n",
       "      <td>1.060000e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5989</th>\n",
       "      <td>2015/6/15</td>\n",
       "      <td>5166.35</td>\n",
       "      <td>5174.42</td>\n",
       "      <td>5176.80</td>\n",
       "      <td>5048.74</td>\n",
       "      <td>5062.99</td>\n",
       "      <td>63780398400</td>\n",
       "      <td>1.060000e+12</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>96 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Day Preclose     Open  Highest   Lowest    Close       Volume  \\\n",
       "4092  2007/8/23  4980.07  5002.84  5050.38  4968.33  5032.49   9930942800   \n",
       "4093  2007/8/24  5032.49  5070.65  5125.36  5052.24  5107.67  10899563600   \n",
       "4094  2007/8/27  5107.67  5144.82  5192.06  5092.08  5150.12  11615424400   \n",
       "4095  2007/8/28  5150.12  5134.14  5209.51  5058.45  5194.69  10543673900   \n",
       "4096  2007/8/29  5194.69  5147.71  5204.53  5063.41  5109.43  10082413900   \n",
       "...         ...      ...      ...      ...      ...      ...          ...   \n",
       "5985   2015/6/9  5131.88  5145.98  5147.45  5042.96  5113.53  72989381800   \n",
       "5986  2015/6/10  5113.53  5049.20  5164.16  5001.49  5106.04  59696900100   \n",
       "5987  2015/6/11  5106.04  5101.44  5122.46  5050.77  5121.59  56399052200   \n",
       "5988  2015/6/12  5121.59  5143.34  5178.19  5103.40  5166.35  62562785400   \n",
       "5989  2015/6/15  5166.35  5174.42  5176.80  5048.74  5062.99  63780398400   \n",
       "\n",
       "             Money  \n",
       "4092  1.530000e+11  \n",
       "4093  1.650000e+11  \n",
       "4094  1.760000e+11  \n",
       "4095  1.670000e+11  \n",
       "4096  1.620000e+11  \n",
       "...            ...  \n",
       "5985  1.150000e+12  \n",
       "5986  1.010000e+12  \n",
       "5987  9.750000e+11  \n",
       "5988  1.060000e+12  \n",
       "5989  1.060000e+12  \n",
       "\n",
       "[96 rows x 8 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data['Close']>5000]\n",
    "#选取收盘价大于5000点的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4092    5032.49\n",
       "4093    5107.67\n",
       "4094    5150.12\n",
       "4095    5194.69\n",
       "4096    5109.43\n",
       "         ...   \n",
       "5985    5113.53\n",
       "5986    5106.04\n",
       "5987    5121.59\n",
       "5988    5166.35\n",
       "5989    5062.99\n",
       "Name: Close, Length: 96, dtype: float64"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data['Close']>5000].Close\n",
    "#对上面数据只要收盘价的数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "日期"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Money</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990-12-19</td>\n",
       "      <td></td>\n",
       "      <td>96.0500</td>\n",
       "      <td>99.9800</td>\n",
       "      <td>95.7900</td>\n",
       "      <td>99.9800</td>\n",
       "      <td>126000</td>\n",
       "      <td>4.940000e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990-12-20</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.3000</td>\n",
       "      <td>104.3900</td>\n",
       "      <td>99.9800</td>\n",
       "      <td>104.3900</td>\n",
       "      <td>19700</td>\n",
       "      <td>8.400000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990-12-21</td>\n",
       "      <td>104.39</td>\n",
       "      <td>109.0700</td>\n",
       "      <td>109.1300</td>\n",
       "      <td>103.7300</td>\n",
       "      <td>109.1300</td>\n",
       "      <td>2800</td>\n",
       "      <td>1.600000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990-12-24</td>\n",
       "      <td>109.13</td>\n",
       "      <td>113.5700</td>\n",
       "      <td>114.5500</td>\n",
       "      <td>109.1300</td>\n",
       "      <td>114.5500</td>\n",
       "      <td>3200</td>\n",
       "      <td>3.100000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990-12-25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.0900</td>\n",
       "      <td>120.2500</td>\n",
       "      <td>114.5500</td>\n",
       "      <td>120.2500</td>\n",
       "      <td>1500</td>\n",
       "      <td>6.000000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8205</th>\n",
       "      <td>2024-07-25</td>\n",
       "      <td>2901.9518</td>\n",
       "      <td>2891.8918</td>\n",
       "      <td>2897.7674</td>\n",
       "      <td>2872.8497</td>\n",
       "      <td>2886.7416</td>\n",
       "      <td>27463950000</td>\n",
       "      <td>2.732820e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8206</th>\n",
       "      <td>2024-07-26</td>\n",
       "      <td>2886.7416</td>\n",
       "      <td>2885.9953</td>\n",
       "      <td>2899.1162</td>\n",
       "      <td>2875.3959</td>\n",
       "      <td>2890.8973</td>\n",
       "      <td>27838753600</td>\n",
       "      <td>2.754430e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8207</th>\n",
       "      <td>2024-07-29</td>\n",
       "      <td>2890.8973</td>\n",
       "      <td>2889.4726</td>\n",
       "      <td>2898.9512</td>\n",
       "      <td>2878.5825</td>\n",
       "      <td>2891.8453</td>\n",
       "      <td>25689972700</td>\n",
       "      <td>2.600950e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8208</th>\n",
       "      <td>2024-07-30</td>\n",
       "      <td>2891.8453</td>\n",
       "      <td>2885.2152</td>\n",
       "      <td>2885.2152</td>\n",
       "      <td>2865.1493</td>\n",
       "      <td>2879.2996</td>\n",
       "      <td>26247883700</td>\n",
       "      <td>2.694770e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8209</th>\n",
       "      <td>2024-07-31</td>\n",
       "      <td>2879.2996</td>\n",
       "      <td>2877.5409</td>\n",
       "      <td>2940.5927</td>\n",
       "      <td>2876.3009</td>\n",
       "      <td>2938.7493</td>\n",
       "      <td>41272341700</td>\n",
       "      <td>4.188720e+11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8210 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Day   Preclose       Open    Highest     Lowest      Close  \\\n",
       "0    1990-12-19               96.0500    99.9800    95.7900    99.9800   \n",
       "1    1990-12-20      99.98   104.3000   104.3900    99.9800   104.3900   \n",
       "2    1990-12-21     104.39   109.0700   109.1300   103.7300   109.1300   \n",
       "3    1990-12-24     109.13   113.5700   114.5500   109.1300   114.5500   \n",
       "4    1990-12-25     114.55   120.0900   120.2500   114.5500   120.2500   \n",
       "...         ...        ...        ...        ...        ...        ...   \n",
       "8205 2024-07-25  2901.9518  2891.8918  2897.7674  2872.8497  2886.7416   \n",
       "8206 2024-07-26  2886.7416  2885.9953  2899.1162  2875.3959  2890.8973   \n",
       "8207 2024-07-29  2890.8973  2889.4726  2898.9512  2878.5825  2891.8453   \n",
       "8208 2024-07-30  2891.8453  2885.2152  2885.2152  2865.1493  2879.2996   \n",
       "8209 2024-07-31  2879.2996  2877.5409  2940.5927  2876.3009  2938.7493   \n",
       "\n",
       "           Volume         Money  \n",
       "0          126000  4.940000e+05  \n",
       "1           19700  8.400000e+04  \n",
       "2            2800  1.600000e+04  \n",
       "3            3200  3.100000e+04  \n",
       "4            1500  6.000000e+03  \n",
       "...           ...           ...  \n",
       "8205  27463950000  2.732820e+11  \n",
       "8206  27838753600  2.754430e+11  \n",
       "8207  25689972700  2.600950e+11  \n",
       "8208  26247883700  2.694770e+11  \n",
       "8209  41272341700  4.188720e+11  \n",
       "\n",
       "[8210 rows x 8 columns]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['Day']=pd.to_datetime(data['Day'],format='%Y/%m/%d')#变成日期的格式\n",
    "#写大写的Y来表示4位数的年份\n",
    "#斜杠格式要与原始数据对应\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数据排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "创新与完善"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Money</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990-12-19</td>\n",
       "      <td></td>\n",
       "      <td>96.0500</td>\n",
       "      <td>99.9800</td>\n",
       "      <td>95.7900</td>\n",
       "      <td>99.9800</td>\n",
       "      <td>126000</td>\n",
       "      <td>4.940000e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990-12-20</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.3000</td>\n",
       "      <td>104.3900</td>\n",
       "      <td>99.9800</td>\n",
       "      <td>104.3900</td>\n",
       "      <td>19700</td>\n",
       "      <td>8.400000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990-12-21</td>\n",
       "      <td>104.39</td>\n",
       "      <td>109.0700</td>\n",
       "      <td>109.1300</td>\n",
       "      <td>103.7300</td>\n",
       "      <td>109.1300</td>\n",
       "      <td>2800</td>\n",
       "      <td>1.600000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990-12-24</td>\n",
       "      <td>109.13</td>\n",
       "      <td>113.5700</td>\n",
       "      <td>114.5500</td>\n",
       "      <td>109.1300</td>\n",
       "      <td>114.5500</td>\n",
       "      <td>3200</td>\n",
       "      <td>3.100000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990-12-25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.0900</td>\n",
       "      <td>120.2500</td>\n",
       "      <td>114.5500</td>\n",
       "      <td>120.2500</td>\n",
       "      <td>1500</td>\n",
       "      <td>6.000000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8205</th>\n",
       "      <td>2024-07-25</td>\n",
       "      <td>2901.9518</td>\n",
       "      <td>2891.8918</td>\n",
       "      <td>2897.7674</td>\n",
       "      <td>2872.8497</td>\n",
       "      <td>2886.7416</td>\n",
       "      <td>27463950000</td>\n",
       "      <td>2.732820e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8206</th>\n",
       "      <td>2024-07-26</td>\n",
       "      <td>2886.7416</td>\n",
       "      <td>2885.9953</td>\n",
       "      <td>2899.1162</td>\n",
       "      <td>2875.3959</td>\n",
       "      <td>2890.8973</td>\n",
       "      <td>27838753600</td>\n",
       "      <td>2.754430e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8207</th>\n",
       "      <td>2024-07-29</td>\n",
       "      <td>2890.8973</td>\n",
       "      <td>2889.4726</td>\n",
       "      <td>2898.9512</td>\n",
       "      <td>2878.5825</td>\n",
       "      <td>2891.8453</td>\n",
       "      <td>25689972700</td>\n",
       "      <td>2.600950e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8208</th>\n",
       "      <td>2024-07-30</td>\n",
       "      <td>2891.8453</td>\n",
       "      <td>2885.2152</td>\n",
       "      <td>2885.2152</td>\n",
       "      <td>2865.1493</td>\n",
       "      <td>2879.2996</td>\n",
       "      <td>26247883700</td>\n",
       "      <td>2.694770e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8209</th>\n",
       "      <td>2024-07-31</td>\n",
       "      <td>2879.2996</td>\n",
       "      <td>2877.5409</td>\n",
       "      <td>2940.5927</td>\n",
       "      <td>2876.3009</td>\n",
       "      <td>2938.7493</td>\n",
       "      <td>41272341700</td>\n",
       "      <td>4.188720e+11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8210 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Day   Preclose       Open    Highest     Lowest      Close  \\\n",
       "0    1990-12-19               96.0500    99.9800    95.7900    99.9800   \n",
       "1    1990-12-20      99.98   104.3000   104.3900    99.9800   104.3900   \n",
       "2    1990-12-21     104.39   109.0700   109.1300   103.7300   109.1300   \n",
       "3    1990-12-24     109.13   113.5700   114.5500   109.1300   114.5500   \n",
       "4    1990-12-25     114.55   120.0900   120.2500   114.5500   120.2500   \n",
       "...         ...        ...        ...        ...        ...        ...   \n",
       "8205 2024-07-25  2901.9518  2891.8918  2897.7674  2872.8497  2886.7416   \n",
       "8206 2024-07-26  2886.7416  2885.9953  2899.1162  2875.3959  2890.8973   \n",
       "8207 2024-07-29  2890.8973  2889.4726  2898.9512  2878.5825  2891.8453   \n",
       "8208 2024-07-30  2891.8453  2885.2152  2885.2152  2865.1493  2879.2996   \n",
       "8209 2024-07-31  2879.2996  2877.5409  2940.5927  2876.3009  2938.7493   \n",
       "\n",
       "           Volume         Money  \n",
       "0          126000  4.940000e+05  \n",
       "1           19700  8.400000e+04  \n",
       "2            2800  1.600000e+04  \n",
       "3            3200  3.100000e+04  \n",
       "4            1500  6.000000e+03  \n",
       "...           ...           ...  \n",
       "8205  27463950000  2.732820e+11  \n",
       "8206  27838753600  2.754430e+11  \n",
       "8207  25689972700  2.600950e+11  \n",
       "8208  26247883700  2.694770e+11  \n",
       "8209  41272341700  4.188720e+11  \n",
       "\n",
       "[8210 rows x 8 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data=data.sort_values(by=\"Day\",axis=0,ascending=True,inplace=False)#按照日期的值来排序\n",
    "data\n",
    "#创新：引入参数axis、inplace"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "设置索引 index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Money</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Day</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1990-12-19</th>\n",
       "      <td></td>\n",
       "      <td>96.0500</td>\n",
       "      <td>99.9800</td>\n",
       "      <td>95.7900</td>\n",
       "      <td>99.9800</td>\n",
       "      <td>126000</td>\n",
       "      <td>4.940000e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-20</th>\n",
       "      <td>99.98</td>\n",
       "      <td>104.3000</td>\n",
       "      <td>104.3900</td>\n",
       "      <td>99.9800</td>\n",
       "      <td>104.3900</td>\n",
       "      <td>19700</td>\n",
       "      <td>8.400000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-21</th>\n",
       "      <td>104.39</td>\n",
       "      <td>109.0700</td>\n",
       "      <td>109.1300</td>\n",
       "      <td>103.7300</td>\n",
       "      <td>109.1300</td>\n",
       "      <td>2800</td>\n",
       "      <td>1.600000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-24</th>\n",
       "      <td>109.13</td>\n",
       "      <td>113.5700</td>\n",
       "      <td>114.5500</td>\n",
       "      <td>109.1300</td>\n",
       "      <td>114.5500</td>\n",
       "      <td>3200</td>\n",
       "      <td>3.100000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-25</th>\n",
       "      <td>114.55</td>\n",
       "      <td>120.0900</td>\n",
       "      <td>120.2500</td>\n",
       "      <td>114.5500</td>\n",
       "      <td>120.2500</td>\n",
       "      <td>1500</td>\n",
       "      <td>6.000000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-25</th>\n",
       "      <td>2901.9518</td>\n",
       "      <td>2891.8918</td>\n",
       "      <td>2897.7674</td>\n",
       "      <td>2872.8497</td>\n",
       "      <td>2886.7416</td>\n",
       "      <td>27463950000</td>\n",
       "      <td>2.732820e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-26</th>\n",
       "      <td>2886.7416</td>\n",
       "      <td>2885.9953</td>\n",
       "      <td>2899.1162</td>\n",
       "      <td>2875.3959</td>\n",
       "      <td>2890.8973</td>\n",
       "      <td>27838753600</td>\n",
       "      <td>2.754430e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-29</th>\n",
       "      <td>2890.8973</td>\n",
       "      <td>2889.4726</td>\n",
       "      <td>2898.9512</td>\n",
       "      <td>2878.5825</td>\n",
       "      <td>2891.8453</td>\n",
       "      <td>25689972700</td>\n",
       "      <td>2.600950e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-30</th>\n",
       "      <td>2891.8453</td>\n",
       "      <td>2885.2152</td>\n",
       "      <td>2885.2152</td>\n",
       "      <td>2865.1493</td>\n",
       "      <td>2879.2996</td>\n",
       "      <td>26247883700</td>\n",
       "      <td>2.694770e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-31</th>\n",
       "      <td>2879.2996</td>\n",
       "      <td>2877.5409</td>\n",
       "      <td>2940.5927</td>\n",
       "      <td>2876.3009</td>\n",
       "      <td>2938.7493</td>\n",
       "      <td>41272341700</td>\n",
       "      <td>4.188720e+11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8210 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             Preclose       Open    Highest     Lowest      Close  \\\n",
       "Day                                                                 \n",
       "1990-12-19               96.0500    99.9800    95.7900    99.9800   \n",
       "1990-12-20      99.98   104.3000   104.3900    99.9800   104.3900   \n",
       "1990-12-21     104.39   109.0700   109.1300   103.7300   109.1300   \n",
       "1990-12-24     109.13   113.5700   114.5500   109.1300   114.5500   \n",
       "1990-12-25     114.55   120.0900   120.2500   114.5500   120.2500   \n",
       "...               ...        ...        ...        ...        ...   \n",
       "2024-07-25  2901.9518  2891.8918  2897.7674  2872.8497  2886.7416   \n",
       "2024-07-26  2886.7416  2885.9953  2899.1162  2875.3959  2890.8973   \n",
       "2024-07-29  2890.8973  2889.4726  2898.9512  2878.5825  2891.8453   \n",
       "2024-07-30  2891.8453  2885.2152  2885.2152  2865.1493  2879.2996   \n",
       "2024-07-31  2879.2996  2877.5409  2940.5927  2876.3009  2938.7493   \n",
       "\n",
       "                 Volume         Money  \n",
       "Day                                    \n",
       "1990-12-19       126000  4.940000e+05  \n",
       "1990-12-20        19700  8.400000e+04  \n",
       "1990-12-21         2800  1.600000e+04  \n",
       "1990-12-24         3200  3.100000e+04  \n",
       "1990-12-25         1500  6.000000e+03  \n",
       "...                 ...           ...  \n",
       "2024-07-25  27463950000  2.732820e+11  \n",
       "2024-07-26  27838753600  2.754430e+11  \n",
       "2024-07-29  25689972700  2.600950e+11  \n",
       "2024-07-30  26247883700  2.694770e+11  \n",
       "2024-07-31  41272341700  4.188720e+11  \n",
       "\n",
       "[8210 rows x 7 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data=data.set_index('Day',drop=True)#扔掉的那一列变成索引\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Money</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Day</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1990-12-19</th>\n",
       "      <td></td>\n",
       "      <td>96.05</td>\n",
       "      <td>99.98</td>\n",
       "      <td>95.79</td>\n",
       "      <td>99.98</td>\n",
       "      <td>126000</td>\n",
       "      <td>4.940000e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-20</th>\n",
       "      <td>99.98</td>\n",
       "      <td>104.30</td>\n",
       "      <td>104.39</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.39</td>\n",
       "      <td>19700</td>\n",
       "      <td>8.400000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-21</th>\n",
       "      <td>104.39</td>\n",
       "      <td>109.07</td>\n",
       "      <td>109.13</td>\n",
       "      <td>103.73</td>\n",
       "      <td>109.13</td>\n",
       "      <td>2800</td>\n",
       "      <td>1.600000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-24</th>\n",
       "      <td>109.13</td>\n",
       "      <td>113.57</td>\n",
       "      <td>114.55</td>\n",
       "      <td>109.13</td>\n",
       "      <td>114.55</td>\n",
       "      <td>3200</td>\n",
       "      <td>3.100000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-25</th>\n",
       "      <td>114.55</td>\n",
       "      <td>120.09</td>\n",
       "      <td>120.25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.25</td>\n",
       "      <td>1500</td>\n",
       "      <td>6.000000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-12-25</th>\n",
       "      <td>1863.8</td>\n",
       "      <td>1865.72</td>\n",
       "      <td>1877.77</td>\n",
       "      <td>1832.36</td>\n",
       "      <td>1852.42</td>\n",
       "      <td>6456614700</td>\n",
       "      <td>4.216964e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-12-26</th>\n",
       "      <td>1852.42</td>\n",
       "      <td>1852.91</td>\n",
       "      <td>1866.63</td>\n",
       "      <td>1840.19</td>\n",
       "      <td>1851.52</td>\n",
       "      <td>5325620100</td>\n",
       "      <td>3.486441e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-12-29</th>\n",
       "      <td>1851.52</td>\n",
       "      <td>1846.30</td>\n",
       "      <td>1856.33</td>\n",
       "      <td>1815.41</td>\n",
       "      <td>1850.48</td>\n",
       "      <td>5502139900</td>\n",
       "      <td>3.709563e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-12-30</th>\n",
       "      <td>1850.48</td>\n",
       "      <td>1851.91</td>\n",
       "      <td>1862.94</td>\n",
       "      <td>1826.98</td>\n",
       "      <td>1832.91</td>\n",
       "      <td>5646622100</td>\n",
       "      <td>3.785263e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-12-31</th>\n",
       "      <td>1832.91</td>\n",
       "      <td>1834.95</td>\n",
       "      <td>1844.37</td>\n",
       "      <td>1814.75</td>\n",
       "      <td>1820.81</td>\n",
       "      <td>5039609900</td>\n",
       "      <td>3.352617e+10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4425 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Preclose     Open  Highest   Lowest    Close      Volume  \\\n",
       "Day                                                                    \n",
       "1990-12-19              96.05    99.98    95.79    99.98      126000   \n",
       "1990-12-20     99.98   104.30   104.39    99.98   104.39       19700   \n",
       "1990-12-21    104.39   109.07   109.13   103.73   109.13        2800   \n",
       "1990-12-24    109.13   113.57   114.55   109.13   114.55        3200   \n",
       "1990-12-25    114.55   120.09   120.25   114.55   120.25        1500   \n",
       "...              ...      ...      ...      ...      ...         ...   \n",
       "2008-12-25    1863.8  1865.72  1877.77  1832.36  1852.42  6456614700   \n",
       "2008-12-26   1852.42  1852.91  1866.63  1840.19  1851.52  5325620100   \n",
       "2008-12-29   1851.52  1846.30  1856.33  1815.41  1850.48  5502139900   \n",
       "2008-12-30   1850.48  1851.91  1862.94  1826.98  1832.91  5646622100   \n",
       "2008-12-31   1832.91  1834.95  1844.37  1814.75  1820.81  5039609900   \n",
       "\n",
       "                   Money  \n",
       "Day                       \n",
       "1990-12-19  4.940000e+05  \n",
       "1990-12-20  8.400000e+04  \n",
       "1990-12-21  1.600000e+04  \n",
       "1990-12-24  3.100000e+04  \n",
       "1990-12-25  6.000000e+03  \n",
       "...                  ...  \n",
       "2008-12-25  4.216964e+10  \n",
       "2008-12-26  3.486441e+10  \n",
       "2008-12-29  3.709563e+10  \n",
       "2008-12-30  3.785263e+10  \n",
       "2008-12-31  3.352617e+10  \n",
       "\n",
       "[4425 rows x 7 columns]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[:'2008-12']\n",
    "#选取2008年12月前面的所有数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Money</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Day</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2024-01-02</th>\n",
       "      <td>2974.9348</td>\n",
       "      <td>2972.7750</td>\n",
       "      <td>2976.2682</td>\n",
       "      <td>2962.2762</td>\n",
       "      <td>2962.2762</td>\n",
       "      <td>30414179300</td>\n",
       "      <td>3.459510e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-01-03</th>\n",
       "      <td>2962.2762</td>\n",
       "      <td>2957.1117</td>\n",
       "      <td>2971.2834</td>\n",
       "      <td>2953.2901</td>\n",
       "      <td>2967.2472</td>\n",
       "      <td>28545594500</td>\n",
       "      <td>3.210180e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-01-04</th>\n",
       "      <td>2967.2472</td>\n",
       "      <td>2965.5087</td>\n",
       "      <td>2966.6828</td>\n",
       "      <td>2936.6347</td>\n",
       "      <td>2954.3486</td>\n",
       "      <td>26498092400</td>\n",
       "      <td>2.962910e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-01-05</th>\n",
       "      <td>2954.3486</td>\n",
       "      <td>2949.8221</td>\n",
       "      <td>2967.9677</td>\n",
       "      <td>2916.7206</td>\n",
       "      <td>2929.1833</td>\n",
       "      <td>30104023900</td>\n",
       "      <td>3.259170e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-01-08</th>\n",
       "      <td>2929.1833</td>\n",
       "      <td>2923.4570</td>\n",
       "      <td>2924.4559</td>\n",
       "      <td>2887.5379</td>\n",
       "      <td>2887.5379</td>\n",
       "      <td>27027505500</td>\n",
       "      <td>2.907310e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-25</th>\n",
       "      <td>2901.9518</td>\n",
       "      <td>2891.8918</td>\n",
       "      <td>2897.7674</td>\n",
       "      <td>2872.8497</td>\n",
       "      <td>2886.7416</td>\n",
       "      <td>27463950000</td>\n",
       "      <td>2.732820e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-26</th>\n",
       "      <td>2886.7416</td>\n",
       "      <td>2885.9953</td>\n",
       "      <td>2899.1162</td>\n",
       "      <td>2875.3959</td>\n",
       "      <td>2890.8973</td>\n",
       "      <td>27838753600</td>\n",
       "      <td>2.754430e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-29</th>\n",
       "      <td>2890.8973</td>\n",
       "      <td>2889.4726</td>\n",
       "      <td>2898.9512</td>\n",
       "      <td>2878.5825</td>\n",
       "      <td>2891.8453</td>\n",
       "      <td>25689972700</td>\n",
       "      <td>2.600950e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-30</th>\n",
       "      <td>2891.8453</td>\n",
       "      <td>2885.2152</td>\n",
       "      <td>2885.2152</td>\n",
       "      <td>2865.1493</td>\n",
       "      <td>2879.2996</td>\n",
       "      <td>26247883700</td>\n",
       "      <td>2.694770e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-31</th>\n",
       "      <td>2879.2996</td>\n",
       "      <td>2877.5409</td>\n",
       "      <td>2940.5927</td>\n",
       "      <td>2876.3009</td>\n",
       "      <td>2938.7493</td>\n",
       "      <td>41272341700</td>\n",
       "      <td>4.188720e+11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>140 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             Preclose       Open    Highest     Lowest      Close  \\\n",
       "Day                                                                 \n",
       "2024-01-02  2974.9348  2972.7750  2976.2682  2962.2762  2962.2762   \n",
       "2024-01-03  2962.2762  2957.1117  2971.2834  2953.2901  2967.2472   \n",
       "2024-01-04  2967.2472  2965.5087  2966.6828  2936.6347  2954.3486   \n",
       "2024-01-05  2954.3486  2949.8221  2967.9677  2916.7206  2929.1833   \n",
       "2024-01-08  2929.1833  2923.4570  2924.4559  2887.5379  2887.5379   \n",
       "...               ...        ...        ...        ...        ...   \n",
       "2024-07-25  2901.9518  2891.8918  2897.7674  2872.8497  2886.7416   \n",
       "2024-07-26  2886.7416  2885.9953  2899.1162  2875.3959  2890.8973   \n",
       "2024-07-29  2890.8973  2889.4726  2898.9512  2878.5825  2891.8453   \n",
       "2024-07-30  2891.8453  2885.2152  2885.2152  2865.1493  2879.2996   \n",
       "2024-07-31  2879.2996  2877.5409  2940.5927  2876.3009  2938.7493   \n",
       "\n",
       "                 Volume         Money  \n",
       "Day                                    \n",
       "2024-01-02  30414179300  3.459510e+11  \n",
       "2024-01-03  28545594500  3.210180e+11  \n",
       "2024-01-04  26498092400  2.962910e+11  \n",
       "2024-01-05  30104023900  3.259170e+11  \n",
       "2024-01-08  27027505500  2.907310e+11  \n",
       "...                 ...           ...  \n",
       "2024-07-25  27463950000  2.732820e+11  \n",
       "2024-07-26  27838753600  2.754430e+11  \n",
       "2024-07-29  25689972700  2.600950e+11  \n",
       "2024-07-30  26247883700  2.694770e+11  \n",
       "2024-07-31  41272341700  4.188720e+11  \n",
       "\n",
       "[140 rows x 7 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['2024-01':'2024-12']\n",
    "#选取2024年1月-12月的所有数据"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
